﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics.Contracts;
using UnitTestUtils.UI;

namespace System.Threading
{
    /// <summary>
    /// Extends the <see cref="EventWaitHandle"/> class.
    /// </summary>
    public static class EventWaitHandleExtensions
    {
        /// <summary>
        /// Applies the default timeout in case no debugger is attached. Otherwise infinite timeout is used.
        /// </summary>
        /// <param name="waitHandle"></param>
        /// <returns><see cref="WaitHandle.WaitOne(TimeSpan)"/></returns>
        public static bool WaitWithTimeout(this EventWaitHandle waitHandle)
        {
            if (waitHandle == null)
                throw new ArgumentNullException("waitHandle");

            return waitHandle.WaitOne(UITestHelper.GetTimeout());
        }
    }
}
